#ifndef _EXCEPTHANDLERTYPE_H_
#define _EXCEPTHANDLERTYPE_H_
#include "SimpleNode.h"
#include "ast/exprType.h"
#include "ast/stmtType.h"
#include "AstTypes.h"
class IVisitor;
class excepthandlerType;
typedef QSharedPointer<excepthandlerType> excepthandlerTypePtr;

class excepthandlerType: public SimpleNode
{
public:
    explicit excepthandlerType(const exprTypePtr& type, const exprTypePtr& name, const StmtTypeList& body, int nodeId=-1);
    virtual ~excepthandlerType();
    
    
    exprTypePtr type_();
    void setType_(const exprTypePtr& type);
    
    exprTypePtr name();
    void setName(const exprTypePtr& name);
    
    StmtTypeList body();
    void setBody(const StmtTypeList& body);
    
    
    virtual Ast::AstTypes type() const;
    virtual QString toString() const;
    virtual void accept(IVisitor* visitor, const SimpleNodePtr& node);
    virtual void traverse(IVisitor* visitor);
private:
    exprTypePtr _type;
    exprTypePtr _name;
    StmtTypeList _body;
};



typedef QListIterator<excepthandlerTypePtr> ExcepthandlerTypePtrListIterator;

class ExcepthandlerTypeList: public QList<excepthandlerTypePtr>
{
public:
    inline ExcepthandlerTypeList() { }
    inline explicit ExcepthandlerTypeList(excepthandlerTypePtr i) { append(i); }
    inline ExcepthandlerTypeList(const ExcepthandlerTypeList &l) : QList<excepthandlerTypePtr>(l) { }
    inline ExcepthandlerTypeList(const QList<excepthandlerTypePtr> &l) : QList<excepthandlerTypePtr>(l) { }

    inline ExcepthandlerTypeList operator+(const ExcepthandlerTypeList &other) const
    { ExcepthandlerTypeList n = *this; n += other; return n; }
    inline ExcepthandlerTypeList &operator<<(excepthandlerTypePtr it)
    { append(it); return *this; }
    inline ExcepthandlerTypeList &operator<<(const ExcepthandlerTypeList &l)
    { *this += l; return *this; }

    QString toString() const
    {
        QString str("ExcepthandlerTypeList(");
        foreach(excepthandlerTypePtr it, *this){
            if (it != NULL){
                str += it->toString()+",";
            }
        }
        str += ")";
        return str;
    }

    void traverse(IVisitor* visitor)
    {
        foreach(excepthandlerTypePtr it, *this){
            if (it != NULL){
                it->accept(visitor, it);
            }
        }
    }
};



#endif